Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make invocation contexts more reliable in testing scenarios. #69

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

peterallenwebb
Copy link
Contributor

resolves #52

Description

Pytest uses some fancy async mechanisms in a way that meant the ContextVar object used to implement InvocationContext access was sometime created more than once. These changes refer to the variable by name rather than object identity, in order to avoid that issue.

Checklist

@peterallenwebb peterallenwebb requested a review from a team as a code owner February 6, 2024 21:11
@@ -26,10 +26,23 @@ def env_secrets(self) -> List[str]:
_INVOCATION_CONTEXT_VAR: ContextVar[InvocationContext] = ContextVar("DBT_INVOCATION_CONTEXT_VAR")


def _reliably_get_invocation_var() -> ContextVar:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures that the ContextVar is identified by name, which works around some fancy async stuff pytest does which cause this module to be loaded multiple times.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, nice discovery with this!

Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🙂

@emmyoop emmyoop added this pull request to the merge queue Feb 6, 2024
Merged via the queue into main with commit 49ee87e Feb 6, 2024
12 checks passed
@emmyoop emmyoop deleted the paw/invocation-context-fix branch February 6, 2024 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants